

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>表单组合</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/layuikn/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/layuikn/style/admin.css" media="all">
</head>

<style>
    #option_zz .layui-form-checkbox{
        margin-bottom: 10px;
    }
    .layui-form-radio{
        margin: 0;
    }
    .layui-form-label{
        width: 180px;
    }
    #option_zz .layui-input:disabled{
        background: rgb(248,248,248);
    }
</style>

<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header"><h2>PG-SGA病人自评</h2></div>
        <div class="layui-card-body" style="padding: 15px;">
            <fieldset class="layui-elem-field" style="padding: 20px;">
                <legend style="font-size: 15px;">个人信息</legend>
                <div class="layui-row">
                    <div class="layui-col-md4">住院号：<span id="huanzhe_hospital_id"></span></div>
                    <div class="layui-col-md4">姓名：<span id="huanzhe_name"></span></div>
                    <div class="layui-col-md4">性别：<span id="huanzhe_gender"></span></div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-md4">科室：<span id="huanzhe_keshi"></span></div>
                    <div class="layui-col-md4">年龄：<span id="huanzhe_age"></span></div>
                    <div class="layui-col-md4">录入日期：<span id="huanzhe_created"></span></div>
                </div>
            </fieldset>
            <form class="layui-form" action="" lay-filter="pgsgahuanzhe-form">
                <fieldset class="layui-elem-field" style="padding: 20px;">
                    <legend style="font-size: 15px;">PG-SGA病人自评</legend>
                    <div class="layui-row">
                        <div class="layui-col-md6">
                            <div style="font-weight: 600;">1、体重</div>
                            <div class="layui-row">
                                <div class="layui-col-md12">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">目前我的体重为</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="tizhong"  placeholder="" autocomplete="off" class="layui-input">
                                        </div>
                                        <div class="layui-form-mid layui-word-aux">kg</div>
                                    </div>
                                </div>
                                <div class="layui-col-md12">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">1个月前我的体重为</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="tizhong1"  placeholder="" autocomplete="off" class="layui-input">
                                        </div>
                                        <div class="layui-form-mid layui-word-aux">kg</div>
                                    </div>
                                </div>
                                <div class="layui-col-md12">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">6个月前我的体重为</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="tizhong6"  placeholder="" autocomplete="off" class="layui-input">
                                        </div>
                                        <div class="layui-form-mid layui-word-aux">kg</div>
                                    </div>
                                </div>
                                <div class="layui-col-md12">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">在过去的2周，我的体重</label>
                                        <div class="layui-input-inline" style="padding-top: 5px;width: 300px;">
                                            <input type="radio" name="tizhongbianhua" score="1" value="1" title="减轻(1)">
                                            <input type="radio" name="tizhongbianhua" score="0" value="0" title="没变化(0)">
                                            <input type="radio" name="tizhongbianhua" score="0" value="2" title="增加(0)">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-md12">
                                    <div style="font-weight: 600;">体重评分</div>
                                    <div class="layui-col-md6">
                                        <div class="layui-col-md12">
                                            <input type="radio" name="tizhongpingfen_type" value="0" title="1个月内体重下降">
                                        </div>
                                        <div class="layui-col-md12" id="option_1_mouth">
                                            <div class="layui-col-md12">
                                                <input type="radio" name="≥10%(4分)" value="" title="≥10%(4分)">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-col-md6">
                                        <div class="layui-col-md12">
                                            <input type="radio" name="tizhongpingfen_type" value="1" title="6个月内体重下降">
                                        </div>
                                        <div class="layui-col-md12" id="option_6_mouth">
                                            <div class="layui-col-md12">
                                                <input type="radio" name="sex" value="1" title="6个月内体重下降">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-col-md12" style="margin-top: 10px;">
                                        <div class="layui-col-md6">
                                            2周内体重下降
                                        </div>
                                        <div class="layui-col-md6">
                                            <input type="checkbox" name="tizhongxiajiang" value="1" score="1" title="1分">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <div style="font-weight: 600;">2、进食情况</div>
                            <div class="layui-row">
                                <div class="layui-col-md12">
                                    <div class="layui-form-item">
                                        在过去1个月里，我的进食情况与平时相比
                                    </div>
                                </div>
                                <div class="layui-row" id="">
                                    <div class="layui-col-md12">
                                        <input type="radio" name="jinshibianhua" score="0" value="0" title="没变化(0)">
                                    </div>
                                    <div class="layui-col-md12">
                                        <input type="radio" name="jinshibianhua" score="0" value="1" title="比以往多(0)">
                                    </div>
                                    <div class="layui-col-md12">
                                        <input type="radio" name="jinshibianhua" score="1" value="2" title="比以往少(1)">
                                    </div>
                                </div>
                            </div>

                            <div class="layui-row">
                                <div class="layui-col-md12">
                                    <div class="layui-form-item" style="margin-top: 15px;">
                                        我目前进食
                                    </div>
                                </div>
                                <div class="layui-row" id="option_mqjs">
                                    <div class="layui-col-md12">
                                        <input type="radio" name="sex" value="男" title="男" checked="">
                                    </div>
                                    <div class="layui-col-md12">
                                        <input type="radio" name="sex" value="男" title="男" checked="">
                                    </div>
                                    <div class="layui-col-md12">
                                        <input type="radio" name="sex" value="男" title="男" checked="">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row" style="margin-top: 20px;">
                        <div class="layui-col-md6">
                            <div style="font-weight: 600;">3、症状</div>
                            <div class="layui-row" style="padding-right: 30px;">
                                <div class="layui-col-md12">
                                    <div class="layui-form-item">
                                        近2周来，我有以下问题，影响我的饮食
                                    </div>
                                </div>
                                <div class="layui-row">
                                    <input hidden value="" type="text" name="zhengzhuang" disabled>
                                    <div class="layui-col-md12" id="option_zz">
                                        <input type="checkbox" name="" value="男" title="男" checked="">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <div style="font-weight: 600;">4、活动和身体功能</div>
                            <div class="layui-row">
                                <div class="layui-col-md12">
                                    <div class="layui-form-item">
                                        在过去的1个月，我的活动
                                    </div>
                                </div>
                                <div class="layui-row" id="option_hdhstgn">
                                    <div class="layui-col-md12">
                                        <input type="radio" name="sex" value="男" title="男" checked="">
                                    </div>
                                    <div class="layui-col-md12">
                                        <input type="radio" name="sex" value="男" title="男" checked="">
                                    </div>
                                    <div class="layui-col-md12">
                                        <input type="radio" name="sex" value="男" title="男" checked="">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-md6">
                            <div class="layui-form-item">
                                <button class="layui-btn" id="total_score_btn" lay-submit="" lay-filter="total_score">四项总分</button>
                                <span id="total_score" style="margin-left: 30px;color: red;"></span>
                            </div>
                        </div>
                    </div>
                </fieldset>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit="" lay-filter="last">上一步</button>
                            <button class="layui-btn" lay-submit="" lay-filter="next">下一步</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>

</div>


<script src="__STATIC__/layuikn/layui/layui.js"></script>
<script>
    layui.config({
        base: '__STATIC__/layuikn/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
        ,ajaxData:'../extends/ajaxData'
        ,getOption:'../extends/getOption'
    }).use(['index', 'jquery', 'ajaxData', 'getOption', 'form', 'laydate'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,ajaxData = layui.ajaxData
            ,getOption = layui.getOption
            ,form = layui.form;

        var pid = sessionStorage.getItem('pid');
        ajaxData.ajaxData('GET',"{:url('patient/info')}?pid=" + pid,{},function (back) {
            if(back.data){
                $('#huanzhe_hospital_id').html(back.data.hospital_id);
                $('#huanzhe_name').html(back.data.name);
                $('#huanzhe_gender').html(back.data.gender);
                $('#huanzhe_keshi').html(back.data.keshi);
                $('#huanzhe_age').html(back.data.age);
                $('#huanzhe_created').html(back.data.created);
            }
        });

        var option_all;


        $.ajax({
            url: "{:url('option/all',[])}",
            type: 'get',
            contentType: 'application/json',
            dataType: 'json',
            async: false, // 同步
            success: function (result) {
                option_all = result;
            }
        });

        var option_1_mouth =  getOption.option(option_all, '体重评分--1月内体重下降');
        //console.log(option_1_mouth);
        var option_6_mouth =  getOption.option(option_all, '体重评分--6月内体重下降');
        //console.log(option_6_mouth);
        var option_mqjs =  getOption.option(option_all, '我目前进食');
        //console.log(option_mqjs);
        var option_zz =  getOption.option(option_all, '症状');
        console.log(option_zz);
        var option_hdhstgn =  getOption.option(option_all, '活动和身体功能');
        //console.log(option_hdhstgn);

        //1个月内体重下降
        var option_1_mouth_html = '';
        $.each(option_1_mouth.children,function (k,v) {
            option_1_mouth_html += '<div class="layui-col-md12">' +
                '<input type="radio" name="tizhongpingfen" value="' + v.id + '" title="' + v.name + '" score="' + v.v + '" >' +
                    '</div>';
        });
        $('#option_1_mouth').html(option_1_mouth_html);

        //6个月内体重下降
        var option_6_mouth_html = '';
        $.each(option_6_mouth.children,function (k,v) {
            option_6_mouth_html += '<div class="layui-col-md12">' +
                '<input type="radio" name="tizhongpingfen" value="' + v.id + '" title="' + v.name + '"score="' + v.v + '" >' +
                '</div>';
        });
        $('#option_6_mouth').html(option_6_mouth_html);

        //我目前进食
        var option_mqjs_html = '';
        $.each(option_mqjs.children,function (k,v) {
            option_mqjs_html += '<div class="layui-col-md12">' +
                '<input type="radio" name="jinshi" value="' + v.id + '" title="' + v.name + '"score="' + v.v + '" >' +
                '</div>';
        });
        $('#option_mqjs').html(option_mqjs_html);

        //症状
        var option_zz_html = '';
        $.each(option_zz.children,function (k,v) {
            if(v.name == '疼痛(3)'){
                option_zz_html +=
                    '<div class="layui-form-item">' +
                        '<div class="layui-form-label" style="width: 86px;padding: 0;">' +
                            '<input type="checkbox" id="zhengzhuang_checkbox_' + v.id + '" lay-filter="zhengzhuang" name="zhengzhuang_op" value="' + v.id + '" title="' + v.name + '"score="' + v.v + '">' +
                        '</div>' +
                        '<div class="layui-input-inline">' +
                            '<input type="text" id="zhengzhuang_text_' + v.id + '" op_name="' + v.name + '" style="margin-left: 20px;" disabled name="zhengzhuang_text_' + v.id + '"  autocomplete="off" class="layui-input">' +
                        '</div>' +
                        '<div style="margin-left: 20px;" class="layui-form-mid layui-word-aux">(部位)</div>' +
                    '</div>';
            }else if(v.name == '其他(1)'){
                option_zz_html +=
                    '<div class="layui-form-item">' +
                        '<div class="layui-form-label" style="width: 86px;padding: 0;">' +
                            '<input type="checkbox" id="zhengzhuang_checkbox_' + v.id + '" lay-filter="zhengzhuang" name="zhengzhuang_op" value="' + v.id + '" title="' + v.name + '"score="' + v.v + '">' +
                        '</div>' +
                        '<div class="layui-input-inline">' +
                            '<input type="text" id="zhengzhuang_text_' + v.id + '" op_name="' + v.name + '" style="margin-left: 20px;" disabled name="zhengzhuang_text_' + v.id + '"  autocomplete="off" class="layui-input">' +
                        '</div>' +
                        '<div style="margin-left: 20px;" class="layui-form-mid layui-word-aux">(如抑郁，经济，牙齿)</div>' +
                    '</div>';
            }else{
                option_zz_html += '<input type="checkbox" lay-filter="zhengzhuang" name="zhengzhuang_op" value="' + v.id + '" title="' + v.name + '"score="' + v.v + '">';
            }

        });
        $('#option_zz').html(option_zz_html);
        form.render();
        //监听复选框
        form.on('checkbox(zhengzhuang)', function (data) {
            var number = $('input[name="zhengzhuang"]'), value = data.value, array = number.val().split(",");
            if (data.elem.checked) {

                number.val(number.val() + value + ",");
            } else {
                var newnumber = "";
                for (var i = 0; i < array.length; i++) {
                    var str = array[i];
                    newnumber += (str != value && str != "" && str != null) ? str + "," : "";
                }
                number.val(newnumber);
            }


            // var text = data.othis[0].innerText;
            // console.log(text)
            //疼痛是否选中
            if($('#zhengzhuang_checkbox_336').prop('checked')){
                $('#zhengzhuang_text_336').removeAttr('disabled');
            }else{
                $('#zhengzhuang_text_336').attr('disabled','disabled');
                $('#zhengzhuang_text_336').val('');
            }
            //其他是否选中
            if($('#zhengzhuang_checkbox_337').prop('checked')){
                $('#zhengzhuang_text_337').removeAttr('disabled');
            }else{
                $('#zhengzhuang_text_337').attr('disabled','disabled');
                $('#zhengzhuang_text_337').val('');
            }
        });

        function initzhengzhuangValue() {
            var param=$("input[name='zhengzhuang']").val(),checkBoxs = $("input[type='checkbox']"), array = param.split(",");
            for (var i = 0; i < array.length; i++) {
                for (var j = 0; j < checkBoxs.length; j++) {
                    var checkbox = $(checkBoxs[j]);
                    if (checkbox.val() == array[i]) {
                        checkbox.attr('checked','checked');
                        break;
                    }
                }
            }
            form.render('checkbox');
        }


        var option_hdhstgn_html = '';
        $.each(option_hdhstgn.children,function (k,v) {
            option_hdhstgn_html += '<div class="layui-col-md12">' +
                '<input type="radio" name="huodong" value="' + v.id + '" title="' + v.name + '"score="' + v.v + '">' +
                '</div>';
        });
        $('#option_hdhstgn').html(option_hdhstgn_html);
        form.render();
        ajaxData.ajaxData('GET',"{:url('pgsgahuanzhe/info')}?pid=" + pid,{},function (back) {

            if(back.data){
                var zhengzhuang_text = back.data.zhengzhuang_text;
                $.each(zhengzhuang_text,function (k,v) {
                    if(v.op_name == '疼痛(3)'){
                        back.data.zhengzhuang_text_336 = v.text;
                    }
                    if(v.op_name == '其他(1)'){
                        back.data.zhengzhuang_text_337 = v.text;
                    }
                })
                //给表单赋值
                form.val("pgsgahuanzhe-form", back.data);
                if($('#zhengzhuang_text_336').val() != ''){
                    $('#zhengzhuang_text_336').removeAttr('disabled');
                }
                if($('#zhengzhuang_text_337').val() != ''){
                    $('#zhengzhuang_text_337').removeAttr('disabled');
                }
            }
            initzhengzhuangValue();
            //form.render();
        });
        form.on('submit(total_score)',function () {
            var tizhongbianhua = 0;
            var tizhongpingfen = 0;
            var tizhongxiajiang = 0;
            var jinshibianhua = 0;
            var jinshi = 0;
            var zhengzhuang = 0;
            var huodong = 0;
            if($("input[name=tizhongbianhua]:checked").attr('score') !== undefined){
                tizhongbianhua = parseInt($("input[name=tizhongbianhua]:checked").attr('score'));
            }
            if($("input[name=tizhongpingfen]:checked").attr('score') !== undefined){
                tizhongpingfen = parseInt($("input[name=tizhongpingfen]:checked").attr('score'));
            }
            if( $("input[name=tizhongxiajiang]").prop("checked")){
                tizhongxiajiang = parseInt($("input[name=tizhongxiajiang]:checked").attr('score'));
            }
            if($("input[name=jinshibianhua]:checked").attr('score') !== undefined){
                jinshibianhua = parseInt($("input[name=jinshibianhua]:checked").attr('score'));
            }
            if($("input[name=jinshi]:checked").attr('score') !== undefined){
                jinshi = parseInt($("input[name=jinshi]:checked").attr('score'));
            }
            if($("input[name=huodong]:checked").attr('score') !== undefined){
                huodong = parseInt($("input[name=huodong]:checked").attr('score'));
            }

            //alert($("input[name=tizhongxiajiang]").prop("checked"))


            $("input[name=zhengzhuang_op]").each(function (k,v) {
                if($(this).prop('checked')){
                    zhengzhuang += parseInt($(this).attr('score'));
                }
            });

            $('#total_score').html(tizhongbianhua + tizhongpingfen + tizhongxiajiang + jinshibianhua + jinshi + zhengzhuang + huodong + '分');
            //var tizhongxiajiang =
            // alert(tizhongbianhua)
            // alert(tizhongpingfen)
            // alert(jinshibianhua)

            return false;
        })
        form.on('submit(last)',function(data){
            if(pid == 'null') return  false;
            window.location.href = "{:url('renticeliang/show')}";
            return  false;
        });
        /* 监听提交 */
        form.on('submit(next)', function(data){
            data.field.zhengzhuang_text = [];
            if(data.field.zhengzhuang_text_336 != ''){
                data.field.zhengzhuang_text.push({
                    'op_id':336,
                    'op_name':$('#zhengzhuang_text_336').attr('op_name'),
                    'text':data.field.zhengzhuang_text_336
                })
            }
            if(data.field.zhengzhuang_text_337 != ''){
                data.field.zhengzhuang_text.push({
                    'op_id':337,
                    'op_name':$('#zhengzhuang_text_337').attr('op_name'),
                    'text':data.field.zhengzhuang_text_337
                })
            }
            console.log(data.field);
            if(pid == 'null') return  false;
            ajaxData.ajaxData('POST', "{:url('pgsgahuanzhe/update')}?pid=" + pid, data.field,function (back) {
                console.log(data.field);
                if(back.code == 200){
                    window.location.href = "{:url('pgsgayisheng/show')}";
                }else{
                    layer.msg(back.msg, {icon: 5});
                }
            });
            // parent.layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // })
            return false;
        });

    });
</script>
</body>
</html>
